<%@ page import="com.lsk.util.UtilUUID" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<html>
<head>
    <title>Title</title>
    <script src="../../js/jquery-3.3.1.min.js" charset="utf-8"></script>
    <script src="../../js/cookie/jquery.cookie.js" charset="utf-8"></script>
    <script src="../../layui-v2.2.5/layui/layui.js" charset="utf-8"></script>
    <script src="/js/layui/form_verify.js?version=<%=UtilUUID.getUUID()%>"></script>
    <link rel="stylesheet" href="../../layui-v2.2.5/layui/css/layui.css" media="all">
    <style>


    </style>
</head>
<body>
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">可提金额</label>
        <div class="layui-input-block">
            <input type="text" name="nowMoney" id="nowMoney"  autocomplete="off"
                 value="${statisticsInfo.residueMoney}" disabled="disabled"  class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">微信实名认证姓名</label>
        <div class="layui-input-block">
            <input type="text" name="realName" id="realName" lay-verify="required" autocomplete="off"
                   placeholder="请输入微信实名认证姓名"  class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">授权手机号</label>
        <div class="layui-input-block">
            <input type="text" name="tel" id="tel" lay-verify="required|phone" autocomplete="off"
                   value="${orgInfo.personTel}" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">验证码</label>
        <div class="layui-input-block">
            <p>
            <input type="text" name="verificationCode" id="verificationCode" lay-verify="required|number" autocomplete="off"
                  style="width: 10%;Float:left;" placeholder="请输入验证码"  class="layui-input">
            <button class="layui-btn" type="button" style="Float:left; margin-left: 5%"  onclick="getVerificationCode(this)">获取验证码</button>
            </p>
        </div>
    </div>
<script>
    var code=-1;
    var wait=60;
    function time(o){
        if (wait==0) {
            o.removeAttribute("disabled");
            o.innerHTML="获取验证码";
            o.style.backgroundColor="#009688";
            wait=60;
        }else{
            o.setAttribute("disabled", true);
            o.innerHTML=wait+"秒后重新获取";
            o.style.backgroundColor="#8f8b8b";
            wait--;
            setTimeout(function(){
                time(o)
            },1000)
        }
    }

    function getVerificationCode(o) {
        var tel=$("#tel").val();
        $.ajax({
            url:'/marketing/sendWithdrawRandomNum',
            type:'POST', //GET
            async:true,    //或false,是否异步
            data:{
                tel:$("#tel").val(),
            },
            timeout:5000,    //超时时间
            dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
            beforeSend:function(xhr){
                /*console.log(xhr)
                 console.log('发送前')*/
            },
            success:function(data){
                console.log(data);
                if (data.code=='000000'){
                    code=data.data;
                    layer.msg(data.msg,{time:1000,icon: 6},function () {
                        time(o);
                    });
                }else {
                    layer.msg(data.msg,{time:1000,icon: 5});
                }
                //console.log(data)
            },
            error:function(xhr,textStatus){
                console.log('错误')
                console.log(xhr)
                console.log(textStatus)
            },
            complete:function(){
                //console.log('结束')
            }
        })


    }


</script>

    <div class="layui-form-item">
        <label class="layui-form-label">提现金额</label>
        <div class="layui-input-block">
            <input type="text" name="money" id="money" lay-verify="required|money"   autocomplete="off" placeholder="请输入提现金额"
                   style="width: 10%;float: left"  value="1"  class="layui-input"  onchange="calculation()">
            <button class="layui-btn" type="button"  style="Float:left; margin-left: 5%" >计算手续费</button>
        </div>
    </div>
    <script>
        function calculation() {
            console.log("执行了函数")
            var residueMoney=parseFloat($("#residueMoney").val());//总金额
            var money=parseFloat($("#money").val());//提现额度

            console.log(money);
            var booleanIsMoney=isMoney(money);
            if (booleanIsMoney==false){
                layer.msg("请输入正确的钱数");
                $("#money").focus();
                return false;
            }

            var commission=(money*0.01).toFixed(2);//手续费
            $("#commission").html(commission);
            var realMoney=money-commission;//到账金额

            $("#realMoney").html(realMoney);
        }

    </script>


    <div class="layui-form-item" style="vertical-align:middle;">
        <label class="layui-form-label">手续费</label>
        <div class="layui-input-block">
            <span name="commission" id="commission" class="layui-span" style="font-size: 20px;color: #ff1217; line-height: 34px ">0.01</span>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">实际到账金额</label>
        <div class="layui-input-block">
            <span name="realMoney" id="realMoney" class="layui-span" style="font-size: 20px; color: #ff1217; line-height: 34px">0.99</span>
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
        </div>
    </div>
</form>


<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['form', 'layer'], function(){
        var form = layui.form
            ,layer = layui.layer
        //监听提交
        checkUserName(form);
        form.on('submit(demo1)', function(data){
            if (code!=$("#verificationCode").val()){
                layer.msg("请输入正确的验证码")
                return false;
            }else {
                $.ajax({
                    url:'/marketing/withdraw',
                    type:'POST', //GET
                    async:true,    //或false,是否异步
                    data:{
                        money:$("#money").val(),
                        activityId:'${activityId}',
                        realName:$("#realName").val()
                    },
                    timeout:5000,    //超时时间
                    dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                    beforeSend:function(xhr){
                        /*console.log(xhr)
                         console.log('发送前')*/
                    },
                    success:function(data){
                        console.log(data);
                        if (data.code=='000000'){
                            layer.msg(data.msg,{time:1000,icon: 6},function () {
                                window.location.reload();
                            });
                        }else {
                            layer.msg(data.msg,{time:2000,icon: 5});
                        }
                        //console.log(data)
                    },
                    error:function(xhr,textStatus){
                        console.log('错误')
                        console.log(xhr)
                        console.log(textStatus)
                    },
                    complete:function(){
                        //console.log('结束')
                    }
                })
            }
            return false;
        });



    });
</script>

</body>
</html>
